import 'package:flutter/material.dart';
import '../utils/adapt.dart';
import '../utils/request.dart';

class Channel extends StatefulWidget {
  Channel({Key? key}) : super(key: key);

  @override
  _ChannelState createState() => _ChannelState();
}

class _ChannelState extends State<Channel> {
  var channelList = [];
  void _getChannelData() async {
    var res = await getHttp('/homepage/dragon/ball');
    List arr = res['data'];
    this.setState(() {
      channelList = arr;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this._getChannelData();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: Adapt.px(12)),
      height: Adapt.px(200),
      child: new ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: channelList.length,
        itemBuilder: (context, item) {
          return Container(
            width: Adapt.px(140),
            height: Adapt.px(200),
            child: InkWell(
              onTap: () {
                Navigator.pushNamed(context, "/chaneldetail", arguments: {
                  "channel": channelList[item]['name'],
                  "url": channelList[item]['iconUrl'],
                });
              },
              child: Column(
                children: [
                  Container(
                    decoration: BoxDecoration(
                      color: Color.fromRGBO(2, 20, 100, 0.1),
                      borderRadius: BorderRadius.circular(Adapt.px(46)),
                    ),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(Adapt.px(40)),
                      child: Image.network(
                        channelList[item]['iconUrl'],
                        fit: BoxFit.fill,
                        width: Adapt.px(126),
                        height: Adapt.px(126),
                        color: Colors.blue[300],
                      ),
                    ),
                  ),
                  Text(
                    channelList[item]['name'],
                    style: TextStyle(
                        color: Colors.black, fontSize: Adapt.px(24), height: 2),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
